/*
 *  Copyright (C) 2012 Компания ВИТ. web: http://diasled.ru Е-mail:  vit@diasled.ru
 * 
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 * 
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 * 
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 * 
 */
package ru.apertum.diasled.redactor;

import ru.apertum.diasled.cfg.Outline;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.Set;
import javax.swing.ComboBoxModel;
import javax.swing.event.ListDataListener;
import ru.apertum.diasled.common.Uses;
//import ru.apertum.diasled.forms.FRedactor.Outline;

/**
 *
 * @author Evgeniy Egorov
 */
public class ComboBoxOutlineModel implements ComboBoxModel {

    final private LinkedList<Outline> outlines;

    public ComboBoxOutlineModel(LinkedList<Outline> outlines) {
        this.outlines = outlines;
    }
    private int ind = 0;

    @Override
    public void setSelectedItem(Object anItem) {
        if (anItem instanceof LinkedList) {
            if (outlines.indexOf(anItem) != -1) {
                ind = outlines.indexOf(anItem);
            }
        } else {
            throw new Uses.SilentException("Тип это String ...");
        }
    }

    @Override
    public Outline getSelectedItem() {
        return outlines.get(ind);
    }

    @Override
    public int getSize() {
        return outlines.size();
    }

    @Override
    public Outline getElementAt(int index) {
        return outlines.get(index);
    }
    final Set<ListDataListener> li = new HashSet<>();

    @Override
    public void addListDataListener(ListDataListener l) {
        li.add(l);
    }

    @Override
    public void removeListDataListener(ListDataListener l) {
        li.remove(l);
    }
}
